package pack0825;

import java.io.*;

public class DemoA {
    //字符流读操作
    public static void a(){
        File file = new File("D://a//a.txt");
        try {
            Reader reader = new FileReader(file);
            char[] chars = new char[10];
            int len;
            do {
                len = reader.read(chars);
                String string = new String(chars,0,len);
                System.out.print(string);
            }while (len!=-1);
            reader.close();
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }
    //字符流写操作
    public static void b(){
        File file = new File("D://a//a.txt");
        try {
            Writer writer = new FileWriter(file);
            int i = 0;
            while (i<10){
                writer.write("asdfg\n");
                i++;
            }
            writer.close();
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }
    //字符流复制操作
    public static void c(){
        File file1 = new File("D://a//a.txt");
        File file2 = new File("D://a//b.txt");
        try {
            Reader reader = new FileReader(file1);
            Writer writer = new FileWriter(file2);
            char[] chars = new char[20];
            while ((reader.read(chars))!=-1){
                writer.write(chars);
            }
            reader.close();
            writer.close();
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }

    public static void main(String[] args){
        c();
    }
}
